package edu.gdin.ecommerce.dao;

import java.util.List;

import org.springframework.stereotype.Component;

import edu.gdin.ecommerce.model.DicType;
import edu.gdin.ecommerce.util.Pager;

@Component("dicTypeDAO")
public class DicTypeDAO extends BaseDAO {
	
	public Pager queryDicTypeByNameOrDesc(String name, String desc, int currentPage){
		
		String hql = "from DicType d where 1=1 ";
		
		hql += name.equals("") ? "" : "and d.name like '%" + name +"%'";
		hql += desc.equals("") ? "" : "and d.typeDesc like '%" + desc +"%'";
		
		return	this.getPage(hql, currentPage);
	}

	public boolean saveDicType(DicType type) {
		try{
			this.insert(type);
			return true;
		}
		catch(Exception e){
			return false;
		}
	}

	@SuppressWarnings("unchecked")
	public List<DicType> queryAllTypes(){
		String hql = "from DicType p";
		return  (List<DicType>) this.query(hql);
	}
}
